package ma.umi.fs.js2a.serial;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ArdaNative {

	public static void copyFile(InputStream in, String to) {
		OutputStream out = null;
		try {
			out = new FileOutputStream(to);
			while (true) {
				int data = in.read();
				if (data == -1) {
					break;
				}
				out.write(data);
			}
			in.close();
			out.close();
		} catch (IOException ex) {
			Logger.getLogger(ArdaNative.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException ex) {
					Logger.getLogger(ArdaNative.class.getName()).log(
							Level.SEVERE, null, ex);
				}
			}
			if (out != null) {
				try {
					out.close();
				} catch (IOException ex) {
					Logger.getLogger(ArdaNative.class.getName()).log(
							Level.SEVERE, null, ex);
				}
			}
		}
	}
}
